package com.cd826dong.clouddemo.provider.api;

import com.cd826dong.clouddemo.mq.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserEndPoint {

    @Value("${server.port}")
    private String servicePort;

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/{names}", method = RequestMethod.GET)
    public List<String> names(@PathVariable String names) throws InterruptedException{
        String[] split = names.split(",");
        //Thread.sleep(3000);
        System.out.println("合并请求，users:" + names + ",from:" + servicePort);
        return Arrays.asList(split);

    }

    @RequestMapping(value = "/save/{name}", method = RequestMethod.GET)
    public String saveuser(@PathVariable String name) throws InterruptedException{
        userService.save(name);
        return "OK";
    }

    
}
